home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch17 / pi / catmull / catmull.pi < prev    next >
Encoding:
Text File  |  1994-08-05  |  3.9 KB  |  136 lines

  1. // Scene File: CATMULL.PI
  2. // Author: Rob McGregor
  3.  
  4. // Uses Catmull-Rom spline interpolation *through*
  5. // key frame points to calculate an object's path... 
  6.  
  7. include "..\..\..\colors.inc"
  8. include "..\..\..\texture.inc"
  9. include "..\..\..\stones.inc"
  10.  
  11. // Set up the camera
  12. viewpoint {
  13.   from       <0, 0, -12>
  14.   at         <0, 0, 0>
  15.   up         <0, 1, 0>
  16.   angle      45
  17.   resolution 320,200
  18.   aspect     1.6
  19. }
  20.  
  21. // Define the range of the animation
  22. start_frame 0
  23. end_frame   49
  24. outfile     "catml"
  25.  
  26. /******************************************************** 
  27.    The control points are:
  28.    
  29.    <0, 0, 0>, <1.6, 2.8, 0>, <3.6, 0, 0>, 
  30.    <0.4, -3.2, 0>, <-3.2, -0.4, 0>, <0, 0, 0>
  31.    
  32.    The first and last points are doubled to include them 
  33.    in the interpolation and create a smoother loop.
  34.  
  35.    x-axis: 0, 0, 1.6, 3.6, 0.4, -3.2, 0, 0 
  36.    y-axis: 0, 0, 2.8, 0,  -3.2, -0.4, 0, 0
  37. *********************************************************/
  38.  
  39. // Define the 4 local 3-D control points as arrays
  40. define n1x [0, 0, 1.6, 3.6, 0.4]
  41. define n1y [0, 0, 2.8, 0, -3.2]
  42. define n1z [0, 0, 0, 0, 0]
  43.  
  44. define n2x [0, 1.6, 3.6, 0.4, -3.2]
  45. define n2y [0, 2.8, 0, -3.2, -0.4]
  46. define n2z [0, 0, 0, 0, 0]
  47.  
  48. define n3x [1.6, 3.6, 0.4, -3.2, -0.4]
  49. define n3y [2.8, 0, -3.2, -0.4, 0]
  50. define n3z [0, 0, 0, 0, 0]
  51.  
  52. define n4x [3.6, 0.4, -3.2, 0, 0]
  53. define n4y [0, -3.2, -0.4, 0, 0]
  54. define n4z [0, 0, 0, 0, 0]
  55.  
  56. // Set up the key frames in another array
  57. define KF [0, 9, 19, 29, 39, 49]
  58.  
  59. // Assign the value of "frame" to variable "F"
  60. define F frame
  61.  
  62. // Determine what key frame sequence we're in
  63. if (F <= KF[1])               // <= 9 
  64.   define key 0
  65. if (F > KF[1] && F <= KF[2])  // > 9 && <= 19
  66.   define key 1
  67. if (F > KF[2] && F <= KF[3])  // > 19 && <= 29
  68.   define key 2
  69. if (F > KF[3] && F <= KF[4])  // > 29 && <= 39
  70.   define key 3
  71. if (F > KF[4])                // > 39 
  72.   define key 4
  73.  
  74. // Calculate the value of "t" from the 
  75. // current frame and key frame sequence
  76. define F1 KF[key]
  77. define F2 KF[key + 1]
  78. define t  (F - F1) / (F2 - F1)
  79.  
  80. /****************************************************************
  81.   Calculate the values of the object's location vector using the 
  82.   Catmull-Rom spline equation:
  83.  
  84.    P = t^3 * (-0.5 * P1) + t^3 * (1.5 * P2) + t^3 * (-1.5 * P3) + 
  85.        t^3 * (0.5 * P4) + t2 * P1 + t^2 * (-2.5 * P2) + t^2 * 
  86.        (2 * P3) + t^2 * (-0.5 * P4) + t * (-0.5 * P1) + t * 
  87.        (0.5 * P3) + P2
  88. ****************************************************************/
  89.  
  90. define t2 t * t
  91. define t3 t2 * t
  92.  
  93. define Px t3 * (-0.5 * n1x[key]) + t3 * (1.5 * n2x[key]) + t3 * 
  94.           (-1.5 * n3x[key]) + t3 * (0.5 * n4x[key]) + t2 * 
  95.           n1x[key] + t2 * (-2.5 * n2x[key]) + t2 * (2 * n3x[key]) + 
  96.           t2 * (-0.5 * n4x[key]) + t * (-0.5 * n1x[key]) + t * 
  97.           (0.5 * n3x[key]) + n2x[key]
  98.  
  99. define Py t3 * (-0.5 * n1y[key]) + t3 * (1.5 * n2y[key]) + t3 * 
  100.           (-1.5 * n3y[key]) + t3 * (0.5 * n4y[key]) + t2 * 
  101.           n1y[key] + t2 * (-2.5 * n2y[key]) + t2 * (2 * n3y[key]) + 
  102.           t2 * (-0.5 * n4y[key]) + t * (-0.5 * n1y[key]) + t * 
  103.           (0.5 * n3y[key]) + n2y[key]
  104.  
  105. define Pz t3 * (-0.5 * n1z[key]) + t3 * (1.5 * n2z[key]) + t3 * 
  106.           (-1.5 * n3z[key]) + t3 * (0.5 * n4z[key]) + t2 * 
  107.           n1z[key] + t2 * (-2.5 * n2z[key]) + t2 * (2 * n3z[key]) + 
  108.           t2 * (-0.5 * n4z[key]) + t * (-0.5 * n1z[key]) + t * 
  109.           (0.5 * n3z[key]) + n2z[key]
  110.  
  111. // Now move the sphere to the new location
  112. object {
  113.   sphere <0, 0, 0>, 0.5
  114.   reflective_red
  115.   translate <Px, Py, Pz>
  116. }
  117.  
  118. // Set the sky color and add a little haze
  119. background Grey
  120. haze 0.98, 25, Grey
  121.  
  122. // Lights
  123. light <-5, 30, -100>
  124. light <5, 30, -100>
  125.  
  126. // The floor...
  127. object {
  128.   disc <0, 0, 0>, <0, 1, 0>, 10000
  129.   texture { 
  130.     checker steely_blue, 
  131.     texture { shiny { color white }}
  132.   }
  133.   rotate <0, 25, 0>
  134.   translate <0, -4.5, 0>
  135. }
  136.